package a1_4;

/**
 * 商品项类，包含名称、重量、描述及相关方法
 */
public class Product {
    private String title;       // 商品名称
    private double weight;      // 商品重量
    private String description; // 商品描述
    private double unitPrice;   // 单价（补充：计算金额必需，UML未明确但合理）

    public Product() {}

    public Product(String title, double weight, String description, double unitPrice) {
        this.title = title;
        this.weight = weight;
        this.description = description;
        this.unitPrice = unitPrice;
    }

    // 操作方法：根据数量获取总价
    public double getPriceForQuantity(int quantity) {
        if (quantity < 1) {
            throw new IllegalArgumentException("数量必须大于0");
        }
        return unitPrice * quantity;
    }

    // 操作方法：获取商品重量
    public double getWeight() {
        return this.weight;
    }

    // Getter/Setter
    public String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    public void setWeight(double weight) {
        this.weight = weight;
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public double getUnitPrice() {
        return unitPrice;
    }

    public void setUnitPrice(double unitPrice) {
        this.unitPrice = unitPrice;
    }
}
